package com.example.x.dnuifood_929dx.controller;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.example.x.dnuifood_929dx.R;
import com.example.x.dnuifood_929dx.adapter.OrderAdapter;
import com.example.x.dnuifood_929dx.bean.CommentInfo;
import com.example.x.dnuifood_929dx.listener.onRetrofitListener;
import com.example.x.dnuifood_929dx.model.FoodModel;

import java.util.List;

/**
 * Created by X on 2018/12/4.
 */

public class MyOrderActivity extends BaseActivity  implements onRetrofitListener<List<CommentInfo>> {
    private RecyclerView myorder_rv;
    private ImageView myorder_return;
    private OrderAdapter adapter;
    private FoodModel foodModel;

    @Override
    void initViews() {
        setLayout(R.layout.myordertactivity);
        myorder_return = (ImageView)findViewById(R.id.myorder_return);
        myorder_rv = (RecyclerView)findViewById(R.id.myorder_rv);
        myorder_rv.setLayoutManager(new LinearLayoutManager(MyOrderActivity.this));

    }

    @Override
    void initEvents() {
        myorder_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish(); }
        });
    }

    @Override
    void initData() {
        foodModel = new FoodModel();
        foodModel.getAllOrdersByUser(getUser_id(),this);
    }


    @Override
    public void onSuccess(List<CommentInfo> object, int flag) {
        adapter = new OrderAdapter(MyOrderActivity.this, object, R.layout.shop_item5);
        myorder_rv.setAdapter(adapter);

    }

    @Override
    public void onFailure(String msg) {

    }
}
